package org.study.event.core.util;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.google.common.base.Function;

/***
 * Set工具
 * @author 陈波
 *
 */
public class Sets {
     
	/***
	 * 从collection集合中提取相关数据到set集合中
	 * @param collection
	 * @param function
	 * @return
	 */
	public <T,S> Set<S> transform(Collection<T> collection,Function<? super T, ? extends S> function){
		Set<S> resultSet=new HashSet<>();
		Iterator<T> iterator=collection.iterator();
	    while(iterator.hasNext()){
	    	T t=iterator.next();
	    	resultSet.add(function.apply(t));
	    }
		return resultSet;
	}
}
